package com.hh.servlet;

import com.hh.module.*;
import com.hh.service.CoachService;
import com.hh.service.IndexNewsService;
import com.hh.service.UserInfoService;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.util.List;

@WebServlet("/index")
public class IndexServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
//        1、乱码处理
        req.setCharacterEncoding(StandardCharsets.UTF_8.toString());
        resp.setCharacterEncoding(StandardCharsets.UTF_8.toString());
//          2、获取前端数据
        /*String name = req.getParameter("name");
        String tel = req.getParameter("tel");
        String email = req.getParameter("email");
        String content = req.getParameter("content");*/
//          3、封装前端获取的数据
        /*UserInfo userInfo = UserInfo.builder()
                .name(name)
                .tel(tel)
                .email(email)
                .content(content)
                .build();*/


//        4、逻辑处理
        CoachService coachService = new CoachService();
        IndexNewsService indexNewsService = new IndexNewsService();
        /*UserInfoService userInfoService = new UserInfoService();*/
//        5、逻辑处理后的返回
        //将用户信息存入集合
        /*userInfoService.add(userInfo);*/
        //公司信息
        CompanyModule companyModule = LogoServlet.logo();
        req.setAttribute("companyModule",companyModule);
        //导航信息
        List<NavModule> navModuleList = NavServlet.nav();
        req.setAttribute("navModuleList", navModuleList);
        //教练信息
        List<CoachModule> IndexCoachModule = coachService.getIndexCoachList();
        req.setAttribute("IndexCoachModule",IndexCoachModule);
        //新闻资讯
        List<IndexNewsModule> indexNewsModule = indexNewsService.getIndexNewsModule();
        req.setAttribute("indexNewsModule",indexNewsModule);

//        6、页面转发
        req.getRequestDispatcher("/index.jsp").forward(req,resp);
    }
}
